package com.qf.servlet;

import com.alibaba.druid.util.StringUtils;
import com.qf.service.RegisterService;
import com.qf.service.impl.RegisterServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.rmi.RemoteException;

/**
 * @author chengqiang
 * @Create 2023-12-05-16:32
 * Description:
 */
public class BaseServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=utf-8");

        String mark = req.getParameter("mark");

        if(StringUtils.isEmpty(mark)){
            throw new RemoteException("方法名不存在");
        }
        Class cla = this.getClass();
        try {
            Method method = cla.getDeclaredMethod(mark, HttpServletRequest.class, HttpServletResponse.class);


            method.setAccessible(true);
            method.invoke(this,req,resp);
        } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
            throw new RuntimeException(e);
        }
    }
}
